using System.ComponentModel.DataAnnotations;

namespace MonitorPlatform.Data.Entities
{
    public class AlertRule : BaseEntity
    {
        [Key]
        public Guid RuleId { get; set; } = Guid.NewGuid();

        [Required]
        [StringLength(50)]
        public string AppId { get; set; } = string.Empty;

        [Required]
        [StringLength(200)]
        public string RuleName { get; set; } = string.Empty;

        [StringLength(1000)]
        public string? Description { get; set; }

        [Required]
        [StringLength(50)]
        public string RuleType { get; set; } = string.Empty; // Threshold, Trend, Anomaly

        [Required]
        [StringLength(50)]
        public string MetricType { get; set; } = string.Empty; // Performance, Error, API, Behavior

        [Required]
        [StringLength(20)]
        public string Severity { get; set; } = "Medium"; // Low, Medium, High, Critical

        // Threshold Configuration
        public double? ThresholdValue { get; set; }
        public string? ThresholdOperator { get; set; } // >, <, >=, <=, ==
        public int? TimeWindow { get; set; } // in minutes
        public int? MinOccurrences { get; set; }

        // Condition Configuration (JSON)
        public string? ConditionConfig { get; set; }

        // Notification Configuration
        public bool IsEmailEnabled { get; set; } = false;
        public string? EmailRecipients { get; set; } // JSON array
        public bool IsWebhookEnabled { get; set; } = false;
        public string? WebhookUrl { get; set; }
        public bool IsSmsEnabled { get; set; } = false;
        public string? SmsRecipients { get; set; } // JSON array

        // Alert State
        public bool IsActive { get; set; } = true;
        public bool IsTriggered { get; set; } = false;
        public DateTime? LastTriggered { get; set; }
        public DateTime? LastEvaluated { get; set; }

        // Metadata
        [StringLength(100)]
        public string? CreatedBy { get; set; }

        [StringLength(100)]
        public string? ModifiedBy { get; set; }

        // Navigation properties
        public virtual Application Application { get; set; } = null!;
        public virtual ICollection<AlertHistory> AlertHistories { get; set; } = new List<AlertHistory>();
    }
} 